<?php
namespace Tests;

use App\Entities\ActivityModel;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Arr;
use Symfony\Component\HttpFoundation\Response;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;

    protected function getActivityIdByType($rule)
    {
        return ActivityModel::with('activities')
            ->where('rule', $rule)
            ->orderBy('created_at', 'DESC')
            ->firstOrFail()
            ->value('id');
    }

    protected function getValueFromResponseJson(Response $response, $key, $default = null)
    {
        $json = $response->getContent();
        $data = \GuzzleHttp\json_decode($json, true);

        return Arr::get($data, $key, $default);
    }
}